package com.ruicar.afs.cloud.account.common.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruicar.afs.cloud.common.modules.contract.enums.LendingDirection;
import com.ruicar.afs.cloud.common.vo.VoucherEntryVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/6/19 20:10
 */
@TableName("account_voucher_entry")
@Data
public class AccountVoucherEntry {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("唯一标识")
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    @JSONField(
            serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class
    )
    @TableId(
            value = "id",
            type = IdType.ASSIGN_ID
    )
    private Long id;

    @ApiModelProperty("凭证号")
    @NotBlank(message = "凭证号不能为空")
    private String voucherNo ;

    @ApiModelProperty("分录序号")
    @NotBlank(message = "分录序号不能为空")
    private Integer entryNo ;

    @ApiModelProperty("科目代码")
    @NotBlank(message = "科目代码不能为空")
    private String subjectCode ;

    @ApiModelProperty("科目名称")
    @NotBlank(message = "科目名称不能为空")
    private String subjectName ;

    @ApiModelProperty("借贷方向")
    @NotNull(message = "借贷方向不能为空")
    private LendingDirection lendingDirection ;

    @ApiModelProperty("借方金额")
    @NotBlank(message = "借方金额不能为空")
    private BigDecimal debitAmt ;

    @ApiModelProperty("贷方金额")
    @NotBlank(message = "贷方金额不能为空")
    private BigDecimal creditAmt ;

    @ApiModelProperty("摘要")
    @NotBlank(message = "摘要不能为空")
    private String explanation ;

    @TableField(
            fill = FieldFill.INSERT
    )
    private String createBy;
    @JsonFormat(
            timezone = "GMT+8",
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @DateTimeFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @ApiModelProperty("创建时间")
    @TableField(
            fill = FieldFill.INSERT
    )
    private Date createTime;
    @ApiModelProperty("更新者")
    @TableField(
            fill = FieldFill.UPDATE
    )
    private String updateBy;
    @JsonFormat(
            timezone = "GMT+8",
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @DateTimeFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @ApiModelProperty("更新时间")
    @TableField(
            fill = FieldFill.UPDATE
    )
    private Date updateTime;
    public static AccountVoucherEntry convertFrom(VoucherEntryVo voucherEntry){
        AccountVoucherEntry entry = new AccountVoucherEntry();
        entry.setLendingDirection(voucherEntry.getLendingDirection());
        entry.setEntryNo(voucherEntry.getOrderNum());
        entry.setSubjectCode(voucherEntry.getSubjectCode());
        entry.setSubjectName(voucherEntry.getSubjectName());
        entry.setExplanation(voucherEntry.getExplanation());
        return entry;
    }
}
